home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / BBS / EZY120_1.ZIP / STRUCT.ARJ / CLIB.ARJ / INITEZY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-09  |  3.4 KB  |  141 lines

  1.  
  2. #include <ezylib.h>
  3. #include <ezycom.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <io.h>
  8. #include <stdlib.h>
  9. #include <share.h>
  10. #include <dir.h>
  11.  
  12. char *SystemPath = NULL;
  13. char *MsgPath = NULL;
  14. char *UserBasePath = NULL;
  15. char *MaintLog = NULL;
  16. int  Node;
  17. ConfigRecord   Config;
  18. ConstantRecord Constant;
  19.  
  20. char *GetSystemPath()
  21. {
  22.   char SPath[MAXDIR];
  23.   char *SysPath;
  24.   SysPath = getenv("EZY");
  25.   if (SysPath) {
  26.     strcpy(SPath,SysPath);
  27.   } else {
  28.     getcwd(SPath,MAXDIR);
  29.   }
  30.   AppendBackslash(SPath);
  31.   SystemPath = strdup(SPath);
  32.   return(SystemPath);
  33. }
  34.  
  35. char *GetMinusSlashParam(char *StrToFind,char *Result)
  36. {
  37.     char TempString[80];
  38.     sprintf(TempString,"-%s",StrToFind);
  39.     if (!*GetParam(TempString,Result)) {
  40.         sprintf(TempString,"/%s",StrToFind);
  41.         GetParam(TempString,Result);
  42.     }
  43.     return(Result);
  44. }
  45.  
  46. int FindMinusSlashParam(char *StrToFind)
  47. {
  48.   int Found = 1;
  49.   char TempString[80];
  50.     sprintf(TempString,"-%s",StrToFind);
  51.     if (!FindParam(TempString)) {
  52.         sprintf(TempString,"/%s",StrToFind);
  53.         Found = FindParam(TempString);
  54.     }
  55.     return(Found);
  56. }
  57.  
  58. char *FindDataFilePath(char *Filename,char *Result)
  59. {
  60.     sprintf(Result,"%s%s.%d",SystemPath,Filename,Node);
  61.     if (!ExistFile(Result)) {
  62.       sprintf(Result,"%s.EZY",Filename);
  63.     if (!ExistFile(Result)) {
  64.             sprintf(Result,"%s%s.EZY",SystemPath,Filename,Node);
  65.             if (!ExistFile(Result)) {
  66.             *Result = '\0';
  67.             };
  68.     }
  69.   };
  70.     return(Result);
  71. }
  72.  
  73. int InitEzycom(char *FailReason,char *ExeCode)
  74. {
  75.   *FailReason = '\0';
  76.   GetSystemPath();
  77.  
  78.   // Get the Node
  79.   {
  80.     Node = 1;
  81.     char NodeNumber[80];
  82.     char *TaskNumber;
  83.     TaskNumber = getenv("TASK");
  84.     if (TaskNumber) {
  85.       Node = atoi(TaskNumber);
  86.     }
  87.     if (*GetMinusSlashParam("NODE",NodeNumber)) {
  88.       Node = atoi(NodeNumber);
  89.     }
  90.     if ((Node < 1) || (Node > 999))
  91.       Node = 1;
  92.   }
  93.   {
  94.     char ConfigPath[MAXPATH];
  95.     FindDataFilePath("CONFIG",ConfigPath);
  96.     if (*ConfigPath) {
  97.       FILE *hConfig;
  98.       if ((hConfig = _fsopen(ConfigPath,"rb",SH_DENYNO)) != NULL) {
  99.         int NumRead = fread(&Config,sizeof(Config),1,hConfig);
  100.         if (NumRead != 1) {
  101.           sprintf(FailReason,"%s reading %s",sys_errlist[errno],ConfigPath);
  102.         } else {
  103.           pPasToC(Config.MsgPath,MsgPath);
  104.           pPasToC(Config.UserBasePath,UserBasePath);
  105.           char Maint[MAXPATH], NodeS[4];
  106.           sprintf(NodeS,"%d",Node);
  107.           PasToC(Config.FileMaint,Maint);
  108.           if (ExeCode)
  109.             ReplaceStr(Maint,"*T",ExeCode);
  110.           MaintLog = strdup(ReplaceStr(Maint,"*N",NodeS));
  111.         }
  112.         fclose(hConfig);
  113.       } else {
  114.         sprintf(FailReason,"%s opening %s",sys_errlist[errno],ConfigPath);
  115.       }
  116.     } else {
  117.       strcpy(FailReason,"CONFIG.EZY not found");
  118.     }
  119.   }
  120.   {
  121.     char ConstantPath[MAXPATH];
  122.     sprintf(ConstantPath,"%sCONSTANT.EZY",SystemPath);
  123.     if (*ConstantPath) {
  124.       FILE *hConstant;
  125.       if ((hConstant = _fsopen(ConstantPath,"rb",SH_DENYNO)) != NULL) {
  126.         int NumRead = fread(&Constant,sizeof(Constant),1,hConstant);
  127.         if (NumRead != 1) {
  128.               sprintf(FailReason,"%s reading %s",sys_errlist[errno],ConstantPath);
  129.         }
  130.              fclose(hConstant);
  131.           } else {
  132.               sprintf(FailReason,"%s opening %s",sys_errlist[errno],ConstantPath);
  133.           }
  134.         } else {
  135.           strcpy(FailReason,"CONSTANT.EZY not found");
  136.       }
  137.   }
  138.   return(!(*FailReason));
  139. }
  140.  
  141.